package com.jifeng.sterilizer.service.impl;

import com.jifeng.sterilizer.entity.DeviceEntity;
import com.jifeng.sterilizer.utils.PageUtils;
import com.jifeng.sterilizer.utils.Query;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.jifeng.sterilizer.dao.VwDeviceDao;
import com.jifeng.sterilizer.entity.VwDeviceEntity;
import com.jifeng.sterilizer.service.VwDeviceService;


@Service("vwDeviceService")
@Slf4j
public class VwDeviceServiceImpl extends ServiceImpl<VwDeviceDao, VwDeviceEntity> implements VwDeviceService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        try {
            QueryWrapper<VwDeviceEntity> queryWrapper = new QueryWrapper<>();
            Object farm = params.get("farm");
            Object type = params.get("type");
            Object number = params.get("number");
            Object name = params.get("name");
            Object status = params.get("status");
            Object produce_time = params.get("produce_time");
            Object sale_time = params.get("sale_time");
            Object mode = params.get("mode");

            if (!farm.equals("")) {
                queryWrapper.like("farm", farm);
            }
            if (!type.equals("")) {
                queryWrapper.like("type", type);
            }
            if (!number.equals("")) {
                queryWrapper.eq("number", number);
            }
            if (!name.equals("")) {
                queryWrapper.like("name", name);
            }
            if (!status.equals("")) {
                queryWrapper.eq("status", status);
            }
            if (!produce_time.equals("")) {
                queryWrapper.like("produce_time", produce_time);
            }
            if (!sale_time.equals("")) {
                queryWrapper.like("sale_time", sale_time);
            }
            if (!mode.equals("")) {
                queryWrapper.eq("mode", mode);
            }
            IPage<VwDeviceEntity> page = this.page(
                    new Query<VwDeviceEntity>().getPage(params),
                    queryWrapper
            );

            return new PageUtils(page);
        } catch (Exception e) {
            e.printStackTrace();
            log.error("方法：{}，错误信息：{}", "查询消毒机列表 PC", e.getMessage());
            return null;
        }
    }

}